package net.chenyan.server.controller.admapi;/**
 * @author chenyan
 * @createTime 2022/4/25 11:20
 * @description description
 */



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.chenyan.commons.core.R;
import net.chenyan.server.po.Singer;
import net.chenyan.server.service.MvService;
import net.chenyan.server.service.SingerService;
import net.chenyan.server.service.UserMvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;



/**
 *@description: TODO
 *@author: chenyan
 *@create: 2022/4/25 11:20
 */
@Slf4j
@Api(tags = {"mv接口"})
@RestController
@RequestMapping(value = "/admapi/mv")

public class MvController {



    @Autowired
    private MvService mvService;
    @Autowired
    private SingerService singerService;
    @Autowired
    private UserMvService userMvService;

    @ApiOperation(value = "根据mv名字查找mv")
    @GetMapping("/findByNameLike")
    public R findByNameLike(@RequestParam(defaultValue = "0")int page, @RequestParam(defaultValue = "5")int size, String name){
        if(name==null){
            return R.error("请输入MV名称");
        }
        // 一定要加 "%"+参数名+"%"
        return R.data(mvService.findAllByNamePage(PageRequest.of(page,size),name));
    }

    @ApiOperation(value = "根据歌手名字搜索mv")
    @GetMapping("/findBySingerName")
    public  R findBySingerName(@RequestParam(defaultValue = "0")int page, @RequestParam(defaultValue = "5")int size, String name){
        if(name==null){
            return R.error("请输入MV名称");
        }
        QueryWrapper<Singer> queryWrapper=new QueryWrapper<>();
        queryWrapper.like("name",name);
        Singer singer=singerService.getOne(queryWrapper);
        if(singer==null){
            return R.error("这个歌手不存在！");
        }
        int singerId=singer.getId();
        return R.data(mvService.findAllBySingerNamePage(singerId,PageRequest.of(page,size)));
    }


    @ApiOperation(value = "根据mv热度展示mv")
    @GetMapping("/findByLikedNum")
    public  R findByLikedNum(@RequestParam(defaultValue = "0")int page, @RequestParam(defaultValue = "5")int size) {
        return R.data(mvService.findAllByLikedNum(PageRequest.of(page,size)));
    }

    @ApiOperation(value = "根据mv最新发布时间展示mv")
    @GetMapping("/findByCreateTime")
    public  R findByCreateTime(@RequestParam(defaultValue = "0")int page, @RequestParam(defaultValue = "5")int size) {
        return R.data(mvService.findAllByCreateTime(PageRequest.of(page,size)));
    }

    @ApiOperation(value = "根据mvid显示mv评论")
    @GetMapping ("/findMvCommentById")
    public  R findMvCommentById(@RequestParam(defaultValue = "0")int page, @RequestParam(defaultValue = "5")int size,int albumId) {
        return R.data(userMvService.findAllMvCommentById(PageRequest.of(page,size),albumId));
    }

}





